// 创建房间界面的控件
var NetControl = require('NetControl');

cc.Class({
    extends: cc.Component,

    properties: {
        m_RoomInfo : [cc.Node],
        m_HuaShui : [cc.Toggle],
    },

    onLoad () {

        // 第1个为默认显示的
        this._BtnShow(0);

        // 划水面板初始化
        this.onHuaShuiJuShuInit();


    },

    // 显示选中的游戏规则界面
    _BtnShow : function(num){
        for(var i=0; i< this.m_RoomInfo.length; ++i){
            if(i == num){
                this.m_RoomInfo[i].active = true;
            }else{
                this.m_RoomInfo[i].active = false;
            }
        }
    },

    // 滑块的按钮
    onHuaShui : function(){
        // 划水面板初始化
        this.onHuaShuiJuShuInit();
        // 显示面板
        this._BtnShow(0);
    },

    onTianShui : function(){
        this._BtnShow(1);
    },

    onJinHua : function(){
        this._BtnShow(2);
    },

    // 创建房间按钮
    onCreatorRoom: function(){
        // // 发送消息的使用方法
        // NetControl.send('createNewRoom', "", (data1)=>{
        //     cc.director.loadScene('huashui');
        // });

        cc.director.loadScene('huashui');
    },

    // 划水面板初始化
    onHuaShuiJuShuInit : function(){
         // 规则面板初始化
        for(var num = 0; num < 12; ++num)
        {
            this.m_HuaShui[num].isChecked = false;
        }
        this.m_HuaShui[0].isChecked = true;
        this.m_HuaShui[2].isChecked = true;
        this.m_HuaShui[4].isChecked = true;
        this.m_HuaShui[6].isChecked = true;
        this.m_HuaShui[8].isChecked = true;
    },

    // 划水面板复选框按钮实现
    onJuShu : function(bl, num){
        if(Number(num) == 0 || Number(num) == 2 || Number(num) == 4 || Number(num) == 6)
        {
            this.m_HuaShui[Number(num)+1].isChecked = false;
        }
        if(Number(num) == 1 || Number(num) == 3 || Number(num) == 5 || Number(num) == 7)
        {
            this.m_HuaShui[Number(num)-1].isChecked = false;
        }
        if(Number(num) == 8 || Number(num) == 9 || Number(num) == 10 || Number(num) == 11)
        {
            for(var i = 0; i < 4; ++i)
            {
                this.m_HuaShui[8+i].isChecked = false;
            }
        }

        this.m_HuaShui[Number(num)].isChecked = true;
    },
});
